/**
 *    Copyright 2009-2020 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.apache.ibatis;

import org.apache.ibatis.aapl.annotation.impl.CountryDictionaryStrategy;
import org.apache.ibatis.aapl.country.*;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.reflection.DefaultReflectorFactory;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.SystemMetaObject;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;
import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

/**
 * @author gu
 * @date 2020/3/3 12:16
 */
public class App {


  public static void main(String[] args) throws IOException {
    // 构建一个源代码的输入流，Reader实质上是一个适配器
    Reader reader = Resources.getResourceAsReader("mybatis-config.xml");

    // 利用建造者模式建造SqlSessionFactory
    SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader);
    SqlSession session = factory.openSession(true);

    StudentMapper mapper = session.getMapper(StudentMapper.class);
    Student student = new Student();
    student.setId(8213);
    student.setSex(3);
    mapper.update(student);
    session.commit();
    session.close();
  }

  public static void tryToInsert(CityMapper mapper) {
    City city = new City();
    city.setName("bbl");
    System.out.println("插入前：" + city);
    mapper.insert(city);
    System.out.println("插入后：" + city);
  }
}
